package com.freak.neteasecloudmusic.modules.mine.fragment;

import com.freak.httphelper.ApiCallback;
import com.freak.httphelper.HttpMethods;
import com.freak.httphelper.RxPresenter;
import com.freak.httphelper.SubscriberCallBack;
import com.freak.neteasecloudmusic.app.api.ApiService;
import com.freak.neteasecloudmusic.commom.constants.Constants;
import com.freak.neteasecloudmusic.modules.mine.entity.MinePlayListEntity;
import com.freak.neteasecloudmusic.net.log.LogUtil;
import com.freak.neteasecloudmusic.utils.ToastUtil;

import io.reactivex.Observable;

public class MySongListPresenter extends RxPresenter<MySongListContract.View> implements MySongListContract.Presenter {
    private ApiService apiService = HttpMethods.getInstance().create(ApiService.class);

    @Override
    public void getPlaylist(String uid) {
        Observable<MinePlayListEntity> observable = apiService.getPlaylist(uid);
        addSubscription(observable, new SubscriberCallBack<>(new ApiCallback<MinePlayListEntity>() {
            @Override
            public void onSuccess(MinePlayListEntity model) {
                if (model.getCode() == Constants.SUCCESS_CODE) {
                    if (mView==null){
                        LogUtil.e("mView 为空");
                    }else {
                        mView.getPlaylistSuccess(model);
                    }
                } else {
                    ToastUtil.shortShow("获取数据失败");
                }
            }

            @Override
            public void onFailure(String msg) {
                mView.showToast(msg);
            }
        }));
    }

}
